1 package uba.db.jdbc;
2
3 import java.sql.Connection;
4 import java.sql.DriverPropertyInfo;
5 import java.sql.SQLException;
6 import java.util.Properties;
7
8 /***
9 * @version $Revision: 1.1.1.1 $
10 */
11 public class Driver implements java.sql.Driver {
12 private static final int MAJOR_VERSION = 0;
13 private static final int MINOR_VERSION = 1;
14
15 private static final String URL_PREFIX = "jdbc:ubadb://";
16
17 private ConnectionFactory connectionFactory;
18
19 private static ConnectionFactory createDefaultConnectionFactory() {
20 return new SocketConnectionFactory();
21 }
22
23 public Driver() {
24 this(createDefaultConnectionFactory());
25 }
26
27 public Driver(ConnectionFactory connectionFactory) {
28 this.connectionFactory = connectionFactory;
29 }
30
31 public Connection connect(String url, Properties info) throws SQLException {
32 return connectionFactory.createConnection(url, info);
33 }
34
35 public boolean acceptsURL(String url) throws SQLException {
36 boolean accepted = url.startsWith(URL_PREFIX);
37
38 if (accepted && URL_PREFIX.length() < url.length()) {
39 String connectionURL = url.substring(URL_PREFIX.length());
40 accepted = connectionFactory.canCreateConnectionTo(connectionURL);
41 }
42
43 return accepted;
44 }
45
46 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
47 DriverPropertyInfo[] driverInfo;
48
49 if (acceptsURL(url)) {
50 driverInfo = connectionFactory.getConnectionPropertiesInformation();
51 } else {
52 driverInfo = new DriverPropertyInfo[0];
53 }
54
55 return driverInfo;
56 }
57
58 public int getMajorVersion() {
59 return MAJOR_VERSION;
60 }
61
62 public int getMinorVersion() {
63 return MINOR_VERSION;
64 }
65
66 public boolean jdbcCompliant() {
67 return false;
68 }
69 }